

clear 
set obs 1 
gen column=.
local cols 9


save ${final_dir}/p_values_`pvers'_`rname'.dta, replace
foreach col of numlist 1/`cols' { 	
    * the 9 columns of the baseline regression 
    
    * ask how often we get coef's that are higher than the original estimate
    * first get the original estimates
    import delimited ${dataset_dir}/montecarlo/original_estimates.csv, clear varnames(1) case(preserve)
    sum estimateL if column==`col'
    local estimateL=`r(mean)'
    sum estimateH if column==`col'
    local estimateH=`r(mean)'
    *and compare to the simulated ones
    use beta_L_`col' beta_H_`col' using ${monte_data_dir}/storage_runs_`pvers'_`rname'.dta, clear
    gen count_it_L=0
    gen count_it_H=0 
    di "LSW `col': `estimateL'"
    di "HSW `col': `estimateH'"
    replace count_it_L=1 if abs(beta_L_`col')>abs(`estimateL')
    replace count_it_H=1 if abs(beta_H_`col')>abs(`estimateH')
    sum count_it_L
    local p_value_L=`r(mean)'
    sum count_it_H
    local p_value_H=`r(mean)'
    
    * save p-values and runs
    clear 
    set obs 1
    gen column=`col'
    gen p_value_L=`p_value_L'
    gen p_value_H=`p_value_H'
    gen run_name="`rname'"
    gen wage_type= "separate wages"
    append using ${final_dir}/p_values_`pvers'_`rname'.dta
    drop if column==.
    sort column
    sleep 300
    save ${final_dir}/p_values_`pvers'_`rname'.dta, replace
}
